﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PowerTest.Admin
{
    public partial class frmQlyGV : Form
    {
        public frmQlyGV()
        {
            InitializeComponent();
        }

        public static string maGVsua;
        private void frmQlyGV_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'powerTestDataSet.viewUserGV' table. You can move, or remove it, as needed.
            this.viewUserGVTableAdapter.FillByMaQuyen(this.powerTestDataSet.viewUserGV,"3");
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void dgvGiaoVien_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvGiaoVien.CurrentRow == null)
            {
                return;
            }
            try
            {
                string ho = dgvGiaoVien.CurrentRow.Cells[1].Value.ToString();
                string dem = dgvGiaoVien.CurrentRow.Cells[2].Value.ToString();
                string ten = dgvGiaoVien.CurrentRow.Cells[3].Value.ToString();
                if (dem == null || dem == "")
                {
                    lblHTen.Text = ho + " " + ten;
                }
                else
                {
                    lblHTen.Text = ho + " " + dem + " " + ten;
                }
            }
            catch
            {
                MessageBox.Show( "Lỗi ! \n", "Canh Bao");
            }
        }

        private void btThem_Click(object sender, EventArgs e)
        {
            new frmThemGV().ShowDialog();
            Dispose();
        }

        private void btSua_Click(object sender, EventArgs e)
        {
            maGVsua = lblMSGV.Text;
            new frmSuaTTGV().ShowDialog();
            Dispose();
        }

        private void btXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc chắn muốn xóa Giáo Viên \""
                      + lblHTen.Text + "\" có Mã Truy Cập \""
                      + lblMSGV.Text + "\" khỏi danh sách",
                      "Xac Nhan", MessageBoxButtons.OKCancel,
                      MessageBoxIcon.Warning) == DialogResult.OK)
            {
                try
                {
                    tblGiaoVienTableAdapter.DeleteQueryByMSGV(lblMSGV.Text);
                    tblChiTietUserTableAdapter.DeleteQueryByID(lblMSGV.Text);
                    this.viewUserGVTableAdapter.FillByMaQuyen(this.powerTestDataSet.viewUserGV, "3");
                }
                catch
                {
                    MessageBox.Show("Lỗi ràng buộc dữ liệu ! Không thể xóa !\n\n Chi tiết\n\n"
                        , "Canh Bao");

                }
            }
        }


    }
}
